package com.leecode.string;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;

public class RestoreIpMain {
	public static void main(String[] args) {
		Deque<String> deque = new ArrayDeque<>();
		test("25525511135", 3, deque);
		System.out.println(deque);
	}

	public static List<String> restoreIpAddresses(String s) {
return null;
	}

	public static boolean test(String s, int leftCount,Deque deque) {

		if (leftCount <= 1) {
			if (1 <= s.length() && s.length() <= 3) {
				if (s.length() >= 2 && s.charAt(0) == '0') {
					return false;
				}

				Integer integer = -1;

				try {
					integer = Integer.valueOf(s);
				} catch (NumberFormatException e) {
					return false;
				}

				if (!(0 <= integer && integer <= 255)) {
					return false;
				}

				deque.addLast(s);
				return true;
			} else {
				return false;
			}
		}


		for (int i = leftCount; i >=1; ) {
			String substring = s.substring(0, i);
			if (test(substring, --i,deque)) {
				deque.addFirst(substring);
			}else{
				continue;
			}
		}

		return false;
	}
}
